package LC.hash;

import java.util.HashMap;

public class LC1 {
    public static void main(String[] args) {
        int[] nums = {2, 7, 11, 15};
        int target = 9;
        int[] res = twoSum(nums, target);
        for (int item :
                res) {
            System.out.println(item);
        }
    }

    public static int[] twoSum(int[] nums, int target) {
        HashMap<Integer, Integer> integerHashMap = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            if (integerHashMap.containsKey(target - nums[i])) {
                return new int[]{integerHashMap.get(target - nums[i]), i};
            }
            integerHashMap.put(nums[i], i);
        }
        return new int[0];
    }
}
